<template>
  <div style="margin-top:18px">
    <setting-card :filterData='filterData' @goSetting='goSetting'></setting-card>
    <div v-show="contentShow"
           style="text-align: center;margin-top:114px;">
        <img :width="320"
             :height="240"
             :src="error">
      </div>
  </div>
</template>

<script>
import error from '@/assets/images/error-page/error.svg'
import SettingCard from '@/view/components/setting-card/setting-card.vue'
import { getDicQuery } from '@/api/setting'
export default {
  name: 'firmware_setting',
  components: {
    SettingCard
  },
  watch: {
    '$route' (newRoute) {
      if (newRoute.name === 'firmware_setting') {
        this.getDicQuery()
      }
    }
  },
  created () {
    this.getDicQuery()
  },
  methods: {
    goSetting (fid) {
      this.$router.push({
        name: 'global_setting_page_' + fid
      })
    },
    getDicQuery () {
      this.dataList = this.allData.filter(item => {
        return this.hasPermission(item.sn)
      })
      let keys = this.dataList.map(item => {
        return item.code !== ''
      })
      if (this.dataList.length > 0) {
        getDicQuery({
          'merchantId': this.$store.state.user.merchantId,
          'msType': '0',
          'dictKeys': keys.join(',')
        }).then(res => {
          if (res.data.status === 200) {
            res.data.data.forEach(data => {
              for (var p in data) {
                this.dataList.forEach(item => {
                  if (p === item.code) {
                    item['updateTime'] = data['updateTime']
                    item['dictValue'] = data[p]
                  }
                })
                this.filterData = this.dataList
              }
            })
          } else {
            this.$Message.error(res.data.message + '服务器' + res.data.status)
          }
        })
      } else {
        this.contentShow = true
      }
    }
  },
  data () {
    return {
      contentShow: false,
      error: error,
      filterData: [],
      dataList: [],
      allData: [
        {
          'code': 'targetFirmwareVersion',
          'description': '统一维护及管理固件物料',
          'manner': 1,
          'position': null,
          'name': '新固件管理',
          'updateTime': null,
          'dictValue': null,
          'sn': 'moms:globalsetting:newfirmware',
          'fid': 19
        },
        {
          'code': 'targetFirmwareVersion',
          'description': '自定义设置固件升级,具有批量操作门店及投币口设置功能',
          'manner': 1,
          'position': null,
          'name': '新固件升级设置',
          'updateTime': null,
          'dictValue': null,
          'sn': 'moms:globalsetting:shopfirmware',
          'fid': 22
        },
        {
          'code': 'swipeReadyPicture',
          'description': '统一维护及管理待机动画物料',
          'manner': 1,
          'position': null,
          'name': '新待机动画管理',
          'updateTime': null,
          'dictValue': null,
          'sn': 'moms:globalsetting:newidlescreen', // 此处需做修改，更改为待机动画管理的权限
          'fid': 5
        },
        {
          'code': 'swipeReadyPicture',
          'description': '自定义更换刷卡器待机动画的物料,具有批量操作门店及投币口设置功能',
          'manner': 1,
          'position': null,
          'name': '新待机动画设置',
          'updateTime': null,
          'dictValue': null,
          'sn': 'moms:globalsetting:shopidlescreen',
          'fid': 23
        },
        {
          'code': 'outTicketType',
          'description': '设置机台出实体票或电子票,具有批量操作门店及投币口设置功能',
          'manner': 1,
          'position': null,
          'name': '新出票类型设置',
          'updateTime': null,
          'dictValue': null,
          'sn': 'moms:globalsetting:shopticket',
          'fid': 20
        },
        {
          'code': 'ledConfig',
          'description': '自定义设置跑马灯功能，具有批量操作门店及投币口设置功能',
          'manner': 1,
          'position': null,
          'name': '新跑马灯设置',
          'updateTime': null,
          'dictValue': null,
          'sn': 'moms:globalsetting:shopmarquee',
          'fid': 21
        }
      ]
    }
  }
}
</script>
